package com.qiji.video.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {
    /*
        自定义线程池。
        IO密集型，线程池数量为核心线程池数两倍，默认拒绝策略
     */
    private static final int COREPOOLSIZE=2;
    private static final int MAXIMUMPOOLSIZE=4;
    private static final Long KEEPALIVETIME=1L;
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(COREPOOLSIZE,MAXIMUMPOOLSIZE,
                KEEPALIVETIME, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                Executors.defaultThreadFactory());
    }
}
